﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace HeritageAcademy.Window
{
	/// <summary>
	/// Window frame class.
	/// </summary>
	public partial class WindowFrame
    {
        #region Ctor

        public WindowFrame()
        {
            InitializeComponent();
            Loaded += WindowFrame_Loaded;
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Register drag window handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void WindowFrame_Loaded(object sender, RoutedEventArgs e)
        {
            dragTarget.MouseLeftButtonDown += dragTarget_MouseLeftButtonDown;
            MouseDoubleClick += WindowFrame_MouseDoubleClick;
        }

        /// <summary>
        /// Window movement handler.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Mouse button event arguments</param>
        void dragTarget_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Application.Current.MainWindow.DragMove();
        }

        /// <summary>
        /// Window state change event handler.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Mouse button event arguments</param>
        void WindowFrame_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (e.GetPosition(this).Y < 80.0)
            {
                if (Application.Current.MainWindow.WindowState == WindowState.Maximized)
                    Application.Current.MainWindow.WindowState = WindowState.Normal;
                else if (Application.Current.MainWindow.WindowState == WindowState.Normal)
                    Application.Current.MainWindow.WindowState = WindowState.Maximized;
            }
        }

        /// <summary>
        /// Minimize window button click handler.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Routed event arguments</param>
        void minimize_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.MainWindow.WindowState = WindowState.Minimized;
        }

        /// <summary>
        /// Maximize window button click handler.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Routed event arguments</param>
        void maximize_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.MainWindow.WindowState = WindowState.Maximized;
        }

        /// <summary>
        /// Restore window button click handler.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Routed event arguments</param>
        void restore_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.MainWindow.WindowState = WindowState.Normal;
        }

        /// <summary>
        /// Close window button click handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void close_Click(object sender, RoutedEventArgs e)
        {
            // Close app
            Application.Current.MainWindow.Close();
        }

        #endregion
    }
}